package src;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Testes {

	
	public static void main(String[] args) {
		try {
			
			
			DatagramSocket serverSocket = new DatagramSocket(24000);
			 
			DatagramSocket clientSocket = new DatagramSocket( 25000);
			clientSocket.setSoTimeout(1);
			byte[] data ={1,1,2,3,4,5,6,7,8,9};
			byte[] data1 ={2,1,2,3,4,5,6,7,8,9};
			byte[] data2 ={3,1,2,3,4,5,6,7,8,9};
			DatagramPacket packet = new DatagramPacket(data,10,InetAddress.getByName("127.0.0.1"),25000);
			DatagramPacket p = new DatagramPacket(new byte[9],9);
			
			serverSocket.send(packet);
			packet = new DatagramPacket(data1,10,InetAddress.getLocalHost(),25000);
			serverSocket.send(packet);
			packet = new DatagramPacket(data2,10,InetAddress.getLocalHost(),25000);
			serverSocket.send(packet);
			clientSocket.setReceiveBufferSize(100000);
			System.out.println(clientSocket.getReceiveBufferSize());
			try {
				Thread.sleep(1000);
				clientSocket.receive(p);
				for (int i = 0; i < p.getData().length; i++) {
					System.out.print( p.getData()[i] + " - ");
				}
				System.out.println();
				Thread.sleep(1000);
				clientSocket.receive(p);
				System.out.println(p.getData()[0]);
				Thread.sleep(1000);
				clientSocket.receive(p);
				System.out.println(p.getData()[0]);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		} catch (SocketException e) {
			System.out.println(e.getCause());
		} catch (IOException e) {
			System.out.println(e.getMessage());
		} 
	}
	
	
}
